package cn.iocoder.yudao.module.ad.order.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.business.basic.service.impl.MemberScopeService;
import cn.iocoder.yudao.module.ad.order.dal.dataobject.AdPlanOrderDO;
import cn.iocoder.yudao.module.ad.order.dal.mysql.AdPlanOrderMapper;
import cn.iocoder.yudao.module.ad.order.vo.AdminAdPlanOrderQueryDTO;
import cn.iocoder.yudao.module.ad.order.vo.AdminAdPlanOrderVO;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;
import java.util.Map;

/**
 * 广告投放订单 Service 实现类
 *
 * @author 山野羡民
 */
@Slf4j
@Service
@Validated
public class AdminAdPlanOrderServiceImpl extends MemberScopeService<AdPlanOrderDO, AdminAdPlanOrderVO, AdminAdPlanOrderQueryDTO> implements AdminAdPlanOrderService {
    @Resource
    private AdPlanOrderMapper adPlanOrderMapper;

    @Resource
    private MemberUserApi memberUserApi;

    @Override
    protected AdPlanOrderMapper getInjectedMapper() {
        return adPlanOrderMapper;
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<AdPlanOrderDO> buildQueryWrapper(AdminAdPlanOrderQueryDTO param) {
        CoreQueryWrapper<AdPlanOrderDO> wrapper = super.buildQueryWrapper(param);
        wrapper.eqIfPresent("payed", param.getPayed());
        wrapper.eqIfPresent("trade_no", param.getTradeNo());
        wrapper.eqIfPresent("pay_no", param.getPayNo());
        wrapper.eqIfPresent("plan_id", param.getPlanId());
        wrapper.orderByDesc("id");
        return wrapper;
    }

    @Nonnull
    @Override
    protected Map<Long, UserSimpleVO> getUserSimpleMap(Collection<Long> userIds) {
        return memberUserApi.getUserSimpleMap(userIds);
    }

}